import React, { Component } from 'react';
import { connect } from 'dva';
import { Card, Collapse} from 'antd';
import RecordInfo from './RecordInfo';

export default class HistoryRecord extends Component {

  historyRecord = (historyRecord, version) =>{
    if(!historyRecord ){
      return null
    }else{
      // historyRecord.sort((a, b) => {
      //   return a.versionTestCount < b.versionTestCount;
      // });
      let list = historyRecord.map(r => {
        return <Collapse.Panel header={`第${r.versionTestCount}次提测记录`} key={r.id} >
                <RecordInfo testRecord={r} version={version} recordLog={r.recordLog}/>
         </Collapse.Panel>
        // return <RecordHistoryPanel header={`第${r.versionTestCount}次提测记录`} key={r.id} onClick={this.handleHistoryCollapse}></RecordHistoryPanel>
      });
      return list;
    }
  }

  
  render() {
    
    const { historyRecordList, version } = this.props;
    const lastRecord = historyRecordList && historyRecordList.length > 0 ? historyRecordList[0] : undefined;
    const lastRecordId = lastRecord  ? lastRecord.id : 0;

    return (
              <Card title="累计历史提测记录" style={{ marginBottom: 24 }} bordered={false}>
                <Collapse defaultActiveKey={[`${lastRecordId}`]} onChange={this.props.handleHistoryCollapse} >
                  {this.historyRecord(historyRecordList, version)}
                </Collapse>
              </Card>
            
    );
  }
}
